import cv2
 
# 打开摄像头
camera = cv2.VideoCapture(0)
 
while True:
    # 读取一帧图像
    _, frame = camera.read()
 
    # 显示图像
    cv2.imshow("Camera", frame)
 
    # 等待 1 毫秒，如果用户按下 'q' 键，则退出循环
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
 
# 释放摄像头资源
camera.release()
 
# 销毁窗口
cv2.destroyAllWindows()